package leetcode;

import java.util.Scanner;

/**
 * 8th 中等难度
 * https://leetcode-cn.com/problems/string-to-integer-atoi/description/
 */
public class Atoi {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        System.out.println();
    }

    private int myAtoi(String str){
        int MAX_INT = Integer.MAX_VALUE;
        int MIN_INT = Integer.MIN_VALUE;
        str = str.trim();
        StringBuilder builder = new StringBuilder();
        boolean positive = true;
        boolean oneFlag = false;
        for(char item: str.toCharArray()){
            if(item == 45 && !oneFlag){
                positive = false;
                oneFlag = true;
                continue;
            }else if(item == '+' && !oneFlag){
                positive = true;
                oneFlag = true;
                continue;
            }else if(item >= 48 && item <=57){
                builder.append(item);
                oneFlag = true;
                continue;
            }else{
                break;
            }
        }
        int res = 0;
        if("".equals(builder.toString())){
            res = 0;
            return res;
        }else{
            try{
                if(positive){
                    res = Integer.parseInt(builder.toString());
                }else{
                    res = - Integer.parseInt(builder.toString());
                }
            }catch (Exception e){
                if(positive){
                    res = MAX_INT;
                }else{
                    res = MIN_INT;
                }
            }finally {
                return res;
            }
        }
    }

}
